home *** CD-ROM | disk | FTP | other *** search
- /***********
- NCSA.c
- A program to automatically kill NCSA Telnet settings files.
- By Wade Williams
- williw1@mail.auburn.edu
- WadesWorld@aol.com
-
- Wade Williams holds copyright (1993) to this source code.
- You are free to distribute this utility.
-
- Note to users: You probably have no need whatsoever for this application.
-
- Why use this program? If you're a network administrator who sets up NCSA Telnet,
- you probably spend a lot of time deleting the NCSA Telnet Settings file from the System
- Folder. Rather than having to delete it each time by opening the system folder and
- dragging it to the trash, I wrote this quick hack which deletes the file.
-
- Note to beginning programmers: This is not terribly good style to learn from. I wrote
- this quickly, and for a very specific purpose. As a Macintosh application, it really
- violates a ton of guidelines. There is no interface, the error handling is minimal,
- there is no event handling, it can't background, etc. Again, this application has
- one purpose and one purpose only - to *quickly* delete the file.
-
- *********************/
-
- /***************** Function Prototypes ******************/
- void InitToolBox(void);
- void GetEnv(void);
- void ShowMyDLOG(void);
- void DeleteFile(void);
-
- /***************** GLOBAL VARIABLES ******************/
-
- OSErr errCode; /* For return variables */
- short item;
- SysEnvRec theSysEnv;
- Str255 errString;
-
- #define SYSENVERR 128 /* ID's of our various dialogs and alerts, except delay */
- #define STATDLOG 128
- #define DELAY 1000000
- #define NODLOG 131
- #define NOFILE 130
- #define FILEERR 129
-
-
-
- /***************** INIT TOOLBOX ******************/
-
- void InitToolBox(void)
- {
- /* Init the entire toolbox and in the proper sequence! */
-
- InitGraf (&thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(0L);
- InitCursor();
- MaxApplZone();
- FlushEvents(everyEvent,0);
- }
-
- /***************** GET ENV ******************/
-
- void GetEnv(void)
- {
- /***
- Make a call to SysEnvirons to find out the ID of the
- "blessed" folder (the system folder). We use SysEnvirons
- instead of Gestalt to maintain System 6 compatibility
- ***/
-
- errCode = SysEnvirons(1, &theSysEnv);
-
- if (errCode) /* if there was an error... (not zero) */
- {
- /* convert the error code to a string */
- NumToString(errCode, errString);
- /* Put it in the Alert */
- ParamText(errString, nil, nil, nil);
- /* Display the error alert */
- item=StopAlert(SYSENVERR, nil);
- /* Abort */
- ExitToShell();
- }
- }
-
- /***************** SHOW MY DLOG ******************/
-
- void ShowMyDLOG(void)
- {
- DialogPtr theDialog;
- long i;
- GrafPtr savePort;
-
- /* Be a friendly program, save the port */
- GetPort(&savePort);
-
- /* Get the Deleting Dialog */
- theDialog = GetNewDialog(STATDLOG, nil, (DialogPtr) -1);
- /* if there was not an error (returned a valid ptr) */
- if (theDialog)
- {
- /* Set the port to our dialog */
- SetPort(theDialog);
- /*
- Draw the dialog - necessary because modaldialog() is
- never called
- */
- UpdtDialog(theDialog, theDialog->visRgn);
- /* Delay for a short time so we can see the dialog */
- for (i=0;i<DELAY;i++)
- ;
- /* Get rid of the dialog */
- DisposeDialog(theDialog);
- }
- else
- {
- /* Display the error alert */
- item=StopAlert(NODLOG,nil);
- /* Abort */
- ExitToShell();
- }
-
- /* Like a good program, we reset the port */
- SetPort(savePort);
- }
-
- /***************** DELETE FILE ******************/
-
- void DeleteFile(void)
- {
- /*
- Delete the file, using the ID of the system folder returned by
- SysEnvirons
- */
-
- errCode = FSDelete("\pNCSA Telnet Settings", theSysEnv.sysVRefNum);
-
- /* If there was an error (ie not 0) */
- if (errCode)
- {
- /* if it was file not found */
- if (errCode == -43)
- {
- /* convert the error code to a string */
- NumToString(errCode, errString);
- /* Put it in the alert */
- ParamText(errString, nil, nil, nil);
- /* display the alert */
- item=CautionAlert(NOFILE,nil);
- /* Abort */
- ExitToShell();
- }
- else /* if it was some other file system error... */
- {
- /* convert the error code to a string */
- NumToString(errCode, errString);
- /* Put it in the alert */
- ParamText(errString, nil, nil, nil);
- /* display the alert */
- item=StopAlert(FILEERR,nil);
- /* Abort */
- ExitToShell();
- }
- }
- }
-
- /***************** MAIN ******************/
-
- main()
- {
- InitToolBox();
- GetEnv();
- ShowMyDLOG();
- DeleteFile();
-
-
- }